﻿<navigation:PageView x:Class="Corina.Cydee.Apphub.Views.Devices.DeviceView"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:controls="clr-namespace:Corina.Controls.Silverlight;assembly=Corina.Controls.Silverlight"
                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                     xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                     xmlns:localViewmodel="clr-namespace:Corina.Cydee.Apphub.Viewmodels"
                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                     xmlns:navigation="clr-namespace:Corina.Cydee.Apphub.Base"
                     xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                     xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
                     Title="设备管理"
                     d:DesignHeight="480"
                     d:DesignWidth="640"
                     mc:Ignorable="d">
    <navigation:PageView.DataContext>
        <localViewmodel:DeviceViewmodel />
    </navigation:PageView.DataContext>
    <Grid x:Name="LayoutRoot">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="300" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <TextBlock VerticalAlignment="Center"
                           Style="{StaticResource ControlLabelStyle}"
                           Text="关键字：" />
                <TextBox Grid.Column="1" Text="{Binding Keywords, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

                <Button Grid.Column="3"
                        Width="60"
                        Command="{Binding InsertCommand}"
                        Content="新增" />
            </Grid>

            <toolkit:BusyIndicator Grid.Row="1"
                                   BusyContent="{StaticResource IDS_BUSYCONTENT_LOADING}"
                                   IsBusy="{Binding IsBusy}">
                <sdk:DataGrid Margin="0,12,0,0"
                              AutoGenerateColumns="False"
                              CanUserSortColumns="False"
                              ColumnWidth="*"
                              IsReadOnly="True"
                              ItemsSource="{Binding DisplayCollection}">
                    <sdk:DataGrid.Columns>
                        <sdk:DataGridTextColumn Binding="{Binding DeviceSn}" Header="设备序列号" />
                        <sdk:DataGridTextColumn Binding="{Binding Kind}" Header="设备种类" />
                        <sdk:DataGridTextColumn Binding="{Binding ManufactureDate, StringFormat=\{0:yyyy-MM-dd\}}" Header="生产日期" />
                        <sdk:DataGridTextColumn Binding="{Binding DataModule}" Header="数据传输模块" />
                        <sdk:DataGridTextColumn Binding="{Binding RatePrice}" Header="零售价" />
                        <sdk:DataGridTemplateColumn Header="操作">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel VerticalAlignment="Center" Orientation="Horizontal">
                                        <HyperlinkButton Content="删除">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </HyperlinkButton>
                                    </StackPanel>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                    </sdk:DataGrid.Columns>
                </sdk:DataGrid>
            </toolkit:BusyIndicator>
        </Grid>
        <controls:PromptDialog Title="{StaticResource IDS_ENUM_ENTITYOPERATION_INSERT}"
                               HorizontalContentAlignment="Stretch"
                               VerticalContentAlignment="Stretch"
                               CloseCommand="{Binding CancelCommand}"
                               Visibility="{Binding ShowUpdate,
                                                    Converter={StaticResource BooleanToVisibilityConverter}}"
                               WindowHeight="300"
                               WindowWidth="400">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <StackPanel>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="120" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock HorizontalAlignment="Right"
                                   VerticalAlignment="Center"
                                   Text="设备种类：" />
                        <ComboBox Grid.Column="1"
                                  ItemsSource="{Binding DeviceKindCollection}"
                                  SelectedItem="{Binding SelectedDeviceKind,
                                                         Mode=TwoWay}">
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Name}" />
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>
                    </Grid>

                    <Grid Margin="0,12,0,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="120" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <TextBlock HorizontalAlignment="Right"
                                   VerticalAlignment="Center"
                                   Text="数据传输模块：" />
                        <ComboBox Grid.Column="1"
                                  ItemsSource="{Binding DeviceDataTransferCollection}"
                                  SelectedItem="{Binding SelectedDataModule,
                                                         Mode=TwoWay}">
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Title}" />
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>
                    </Grid>

                    <Grid Margin="0,12,0,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="120" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock HorizontalAlignment="Right"
                                   VerticalAlignment="Center"
                                   Text="设备序列号：" />
                        <TextBox Grid.Column="1" Text="{Binding UpdateEntity.DeviceSn, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    </Grid>

                    <Grid Margin="0,12,0,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="120" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock HorizontalAlignment="Right"
                                   VerticalAlignment="Center"
                                   Text="出产日期：" />
                        <sdk:DatePicker Grid.Column="1"
                                        DisplayDateEnd="{Binding ValidDate}"
                                        SelectedDate="{Binding UpdateEntity.ManufactureDate,
                                                               Mode=TwoWay,
                                                               UpdateSourceTrigger=PropertyChanged}" />
                    </Grid>

                    <Grid Margin="0,12,0,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="120" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock HorizontalAlignment="Right"
                                   VerticalAlignment="Center"
                                   Text="零售价：" />
                        <TextBox Grid.Column="1" Text="{Binding UpdateEntity.RatePrice, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    </Grid>

                </StackPanel>

                <StackPanel Grid.Row="1"
                            HorizontalAlignment="Right"
                            Orientation="Horizontal">
                    <Button Width="60"
                            Margin="12,0"
                            Command="{Binding SubmitCommand}"
                            Content="提交" />
                    <Button Width="60"
                            Command="{Binding CancelCommand}"
                            Content="取消" />
                </StackPanel>
            </Grid>
        </controls:PromptDialog>
    </Grid>
</navigation:PageView>
